package cn.wolfcode.wolf2w.util;

import cn.wolfcode.wolf2w.domain.Region;
import cn.wolfcode.wolf2w.query.QueryObject;
import cn.wolfcode.wolf2w.query.RegionQuery;
import org.springframework.data.domain.*;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Query;

import java.util.List;

public class DBHelper {
    public static <T> Page<T> query(MongoTemplate template, Pageable pageable, Query query, Class<T> clz, QueryObject qo) {
        //查询条件
        //count 总条数
        long count = template.count(query, clz);
        if (count == 0) {
            return Page.empty();
        }
        //list当前页数据
        query.with(pageable);
        List<T> list = template.find(query, clz);
        return new PageImpl<>(list, pageable, count);
    }
}
